 use "$data\women_analysis.dta", clear
 
 tab ITTanalysis, gen(treatment)
 rename treatment1 control
 rename treatment2 treated
 lab var control "dummy for control women"
 lab var treated "dummy for treated women"
 bysort HHID: gen HHIDrepeat=_N
 lab var HHIDrepeat "no. of learners in a HH"
 sort HHIDrepeat
 unique HHID if HHIDrepeat>1
 replace treated=2 if treated==0
 sort HHID treated
 bysort HHID: replace treated=treated[1]
 replace treated=0 if treated==2
 replace control=2 if control==0
 sort HHID control
 bysort HHID: replace control=control[1]
 replace control=0 if control==2
 egen treatcontrolsameHH=rowtotal(treated control)
 lab var treatcontrolsameHH "HHs with and w/o mixed treatment status women"
 lab define treatcontrol 1 "HHs w/o mixed status" 2 "HHs with mixed status"
 lab values treatcontrolsameHH treatcontrol
 unique learnerid if treatcontrolsameHH==2
 unique HHID if treatcontrolsameHH==2
 count if treatcontrolsameHH==2
 
 replace anyhelp=0 if pid_helpedinhome=="T"
 gen tutor=0 if anyhelp!=.
 replace tutor=1 if pid_helpedinhome=="T"
 
 global controlkid childageyears female birthorder
 global controlwoman mbase_ageyears  fdstotal rantime ranerror numberkids
 global controlhh land members adults mbase_electrified  mbase_OB mbase_scheduled

 estimates clear
 ****Table B.5 Panel A
 ivregress 2sls admission_school (participatedTA_IV=ITTanalysis) i.strata $controlkid $controlwoman $controlhh if treatcontrolsameHH==1 & childageyears>=6 & childageyears<=16, cluster(learnerid)
 estimates store adms
 su admission_school if ITTanalysis==0 & treatcontrolsameHH==1 & childageyears>=6 & childageyears<=16
 estadd scalar controlmean=`r(mean)'
 
 foreach i in Dabsentschool dropoffatschool askingforhomework Dtimespenthomework womanhelphomework tutor{
 ivregress 2sls `i' (participatedTA_IV=ITTanalysis) i.strata $controlkid $controlwoman $controlhh if treatcontrolsameHH==1 & childageyears>=6 & childageyears<=16 & admission_school==1, cluster(learnerid)
 est store `i'
 su `i' if ITTanalysis==0 & treatcontrolsameHH==1 & childageyears>=6 & childageyears<=16
 estadd scalar controlmean=`r(mean)'
 }
 
 ****Table B.5 Panel B
 ivregress 2sls Ddays_sick  (participatedTA_IV=ITTanalysis) i.strata $controlkid $controlwoman $controlhh if  treatcontrolsameHH==1 & childageyears<=16, cluster(learnerid)
 estimates store Ddays_sick
 su Ddays_sick if ITTanalysis==0 & treatcontrolsameHH==1 & childageyears<=16
 estadd scalar controlmean=`r(mean)'
 
 ivregress 2sls medicalhelp  (participatedTA_IV=ITTanalysis) i.strata $controlkid $controlwoman $controlhh if Ddays_sick==0 & treatcontrolsameHH==1 & childageyears<=16, cluster(learnerid)
 estimates store medical
 su medicalhelp if ITTanalysis==0 & treatcontrolsameHH==1 & childageyears<=16
 estadd scalar controlmean=`r(mean)'
 
 foreach i in placeofmedicalhelp presence_woman_treatment{
 ivregress 2sls `i' (participatedTA_IV=ITTanalysis) i.strata $controlkid $controlwoman $controlhh if medicalhelp==1 & treatcontrolsameHH==1 & childageyears<=16, cluster(learnerid)
 est store `i'
 su `i' if ITTanalysis==0 & treatcontrolsameHH==1 & childageyears<=16
 estadd scalar controlmean=`r(mean)'
 }
 
 esttab * using "$results\TableB5.xls", stat(controlmean N r2) keep (participatedTA_IV) b(2) se(2) replace

 exit
 
 
 
 



